#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "ohos_init.h"
#include "cmsis_os2.h"
#include "hi_adc.h"
#include "hi_uart.h"
#include "hi_io.h"
#include "hi_gpio.h"
#include "iot_gpio.h"
#include "hi_pwm.h"
#include "iot_pwm.h"
#include "light_control.h"

// 灯
#define RED_GPIO_10 10
#define GREEN_GPIO_11 11
#define BLUE_GPIO_12 12

#define DELAY_US 75000
#define PWM_FREQ_DIVITION 500
#define PWM_PORT_NUM1 (1)
#define PWM_PORT_NUM2 (2)
#define PWM_PORT_NUM3 (3)

#define GPIO_HIGH (1)
#define GPIO_LOW (0)
static int sta;

void light_close(int sta)
{
    if (sta != 4)
    {
        IoTPwmStop(sta);
    }
    else
    {
        IoTPwmStop(PWM_PORT_NUM1);
        IoTPwmStop(PWM_PORT_NUM2);
        IoTPwmStop(PWM_PORT_NUM3);
    }
}

int redTask(int num)
{
    hi_pwm_start(PWM_PORT_NUM1, num, PWM_FREQ_DIVITION);
    usleep(DELAY_US);
    return sta = 1;
}

int greenTask(int num)
{
    hi_pwm_start(PWM_PORT_NUM2, num, PWM_FREQ_DIVITION);
    usleep(DELAY_US);
    return sta = 2;
}

int blueTask(int num)
{
    hi_pwm_start(PWM_PORT_NUM3, num, PWM_FREQ_DIVITION);
    usleep(DELAY_US);
    return sta = 3;
}

int whiteTask(int num)
{
    hi_pwm_start(PWM_PORT_NUM1, num, PWM_FREQ_DIVITION);
    hi_pwm_start(PWM_PORT_NUM2, num, PWM_FREQ_DIVITION);
    hi_pwm_start(PWM_PORT_NUM3, num, PWM_FREQ_DIVITION);
    usleep(DELAY_US);
    return sta = 4;
}
